// facebook 实现一个函数，他输入的是一个数组，其中包含喜欢 该项目的人的名字，返回 值 是如下格式
// [] "no one likes this"
// ["Peter"] "Peter likes this"
// ["Jacob","Alex"] "Jacob and Alex like this"
// ["Max","John","Mark"] "Max, John and Mark like this"
// ["Max","John","Mark","Mak"] "Max,John and 2 others like this"

function likes(names) {
    let templates = [
        'no one likes this',
        '{name} likes this',
        '{name} and {name} like this',
        '{name}, {name} and {name} like this',
        '{name}, {name} and {n} others like this'
    ]
    let idx = Math.min(names.length, 4);
    // console.log(idx);
    let str = templates[idx];
    for (let i = 0; i < names.length; i++) {
        str = str.replace("{name}", names[i])
    }
    return str;
}
console.log(likes([]));
console.log(likes(['a']));
console.log(likes(["Jacob", "Alex"]));
console.log(likes(["Max", "John", "Mark"]));
console.log(likes(["Max", "Jacob", "Mark", "Max"]));